/*
 * @Description:
 * @Version: 2.0
 * @Autor: Seven
 * @Date: 2023-10-19 16:08:00
 * @LastEditors: Seven
 * @LastEditTime: 2023-10-27 16:17:33
 */
import { getOrderGenner } from "@/services/modules/plan";
import { loacalCache } from "@/ultils/func";
import { Form, Input, Modal, Select } from "antd";
import React, { memo, useRef, useEffect } from "react";
const formItemLayout = {
  labelCol: {
    xs: { span: 24 },
    sm: { span: 6 },
  },
  wrapperCol: {
    xs: { span: 24 },
    sm: { span: 18 },
  },
};
const { Option } = Select;
const GenerateModal = memo(
  ({ GenerateVisible, handleCancel, getList, rowInfoData }) => {
    const formRef = useRef();
    const [form] = Form.useForm();
    function onFinish() {
      form
        .validateFields({ validateOnly: true })
        .then(() => {
          let data = form.getFieldsValue();
          getOrderGenner(data, rowInfoData.id).then((res) => {
            if (res.code === 200) {
              getList();
              handleCancel();
            }
          });
        })
        .catch((err) => err);
    }
    useEffect(() => {
      form.setFieldsValue(rowInfoData);
    }, [rowInfoData, form]);
    return (
      <div>
        <Modal
          title="生成故障工单"
          open={GenerateVisible}
          onOk={onFinish}
          onCancel={handleCancel}
        >
          <Form
            {...formItemLayout}
            ref={formRef}
            onFinish={onFinish}
            form={form}
            style={{
              maxWidth: 600,
            }}
          >
            <Form.Item
              name="faultId"
              label="故障提报编号"
              rules={[
                {
                  required: true,
                  message: "请输入你的故障提报编号",
                },
              ]}
            >
              <Input disabled />
            </Form.Item>
            {/* <Form.Item
              name="troubleId"
              label="故障工单编号"
              rules={[
                {
                  required: true,
                  message: "请输入你的故障工单编号",
                },
              ]}
            >
              <Input />
            </Form.Item> */}

            <Form.Item
              name="troubleDesc"
              label="工单描述"
              rules={[
                {
                  required: true,
                  message: "请输入你的工单描述",
                },
              ]}
            >
              <Input />
            </Form.Item>
            <Form.Item
              name="speciality"
              label="专业"
              rules={[
                {
                  required: true,
                  message: "请输入你的专业",
                },
              ]}
            >
              <Select>
                {loacalCache.getCache("DicDataList")?.["falut_speciality"] &&
                  loacalCache
                    .getCache("DicDataList")
                    ?.["falut_speciality"].map((item) => {
                      return (
                        <Option value={item.value} key={item.id}>
                          {item.label}
                        </Option>
                      );
                    })}
              </Select>
            </Form.Item>
            <Form.Item
              name="line"
              label="线路"
              rules={[
                {
                  required: true,
                  message: "请输入你的线路",
                },
              ]}
            >
              <Select>
                {loacalCache.getCache("DicDataList")?.["line"] &&
                  loacalCache.getCache("DicDataList")?.["line"].map((item) => {
                    return (
                      <Option value={item.value} key={item.id}>
                        {item.label}
                      </Option>
                    );
                  })}
              </Select>
            </Form.Item>
            <Form.Item
              name="dept"
              label="部门"
              rules={[
                {
                  required: true,
                  message: "请选择你的部门",
                },
              ]}
            >
              <Select>
                {loacalCache.getCache("DicDataList")["dept"] &&
                  loacalCache.getCache("DicDataList")["dept"].map((item) => {
                    return (
                      <Option value={item.value} key={item.id}>
                        {item.label}
                      </Option>
                    );
                  })}
              </Select>
            </Form.Item>
            <Form.Item
              name="status"
              label="状态"
              rules={[
                {
                  required: true,
                  message: "请输入你的状态",
                },
              ]}
            >
              <Select>
                {loacalCache.getCache("DicDataList")?.["falut_status"] &&
                  loacalCache
                    .getCache("DicDataList")
                    ?.["falut_status"].map((item) => {
                      return (
                        <Option value={item.value} key={item.id}>
                          {item.label}
                        </Option>
                      );
                    })}
              </Select>
            </Form.Item>
            <Form.Item
              name="team"
              label="班组"
              rules={[
                {
                  required: true,
                  message: "请输入你的班组",
                },
              ]}
            >
              <Input />
            </Form.Item>
            <Form.Item
              name="workshop"
              label="车间"
              rules={[
                {
                  required: true,
                  message: "请选择你的车间",
                },
              ]}
            >
              <Select>
                {loacalCache.getCache("DicDataList")["workshop"] &&
                  loacalCache
                    .getCache("DicDataList")
                    ["workshop"].map((item) => {
                      return (
                        <Option value={item.value} key={item.id}>
                          {item.label}
                        </Option>
                      );
                    })}
              </Select>
            </Form.Item>
            <Form.Item
              name="isFinish"
              label="是否完成"
              rules={[
                {
                  required: true,
                  message: "请选择是否完成",
                },
              ]}
            >
              <Select>
                <Option value={0} key={1}>
                  未完成
                </Option>
                <Option value={1} key={2}>
                  已完成
                </Option>
              </Select>
            </Form.Item>
          </Form>
        </Modal>
      </div>
    );
  }
);

export default GenerateModal;
